package com.mediacloud.app.newsmodule.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mediacloud.app.model.news.CatalogItem;
import com.mediacloud.app.newsmodule.R;

import com.mediacloud.app.assembly.pbl.view.AbsXListSeondHeader;
import com.mediacloud.app.newsmodule.activity.LBSCityListChooseActivity;
import com.mediacloud.app.newsmodule.utils.LBSChooseListener;


/**
 * 头部 点了后跳转选择位置 那个
 */
public class LocationChooseHeader extends AbsXListSeondHeader implements View.OnClickListener
{
    Context mContext;
    View mContentView;
    public CatalogItem catalogItem;
    public String tag;
    public LocationChooseHeader(Context context)
    {
        super(context);
        init(context);
    }

    public LocationChooseHeader(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        init(context);
    }

    public LocationChooseHeader(Context context, AttributeSet attrs, int defStyleAttr)
    {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    @Override
    public void setVisiableHeight(int height)
    {
        LayoutParams layoutParams= (LayoutParams) mContentView.getLayoutParams();
        if(layoutParams==null)
        {
            layoutParams=new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,height);
        }
        layoutParams.height=height;
        mContentView.setLayoutParams(layoutParams);
    }

    @Override
    public int getVisibleHeight()
    {
        return mContentView.getHeight();
    }

    protected void init(Context context)
    {
        mContext=context;
        View view=LayoutInflater.from(mContext).inflate(R.layout.aappfactory_lbslist_switchheader,this);
        mContentView=view.findViewById(R.id.contentView);
        View chooseHeader=view.findViewById(R.id.chooseHeader);
        setGravity(Gravity.BOTTOM);
        chooseHeader.setOnClickListener(this);
        setVisiableHeight(0);
    }

    /**
     * 点击跳转到另外一个页面
     * @param v
     */
    @Override
    public void onClick(View v)
    {
        if(catalogItem!=null)
        {
            Intent intent=new Intent();
            intent.setClass(mContext, LBSCityListChooseActivity.class);
            intent.putExtra("data",catalogItem);
            intent.putExtra("tag",tag);
            ((Activity)mContext).startActivityForResult(intent, LBSChooseListener.Request);
        }
    }
}